﻿/// <reference path="../../release/ajaxstack-core.js"/>
/// <reference path="../../release/jsApp.js"/>

function MasterController(app)
{
	MasterController.$baseConstructor.call(this, app, MasterController.TagId);

	this.controller = null;
}
MasterController.extend(UiController, { type: 'MasterController' },
{
	getControllers: function()
	{
		return this.controller ? [this.controller] : [];
	},

	loadPath: function(path)
	{
		this.path = path;
		if (this.controller && this.getName() == path.getName())
		{
			this.log.debug(this.getName() + ": is already loaded for path: " + path);
			return;
		}
		var ctor = MasterController.getController(path.getName());
		if (ctor)
		{
			this.controller = new ctor(this.app, MasterController.TagId);
			this.log.debug("loading '" + this.controller.getName() + "' for path: " + path);
			this.controller.loadPath(path);
			return;
		}

		//Call the base path to load the static page for paths without dedicated controllers
		MasterController.$base.loadPath.call(this, path);
	}
});

MasterController.TagId = "#content";
UiController.registerControllers(MasterController, [
		AjaxExamplesPageController	], 	{ canHandlePathFn: UiController.handleAnyPath });